<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
// 
//  admin_activity.php
//  www.6block.com
//  
//  Created by Will_Lee on 2011-05-19.
//  Copyright 2011 lishuzu. All rights reserved.
// 

class Admin_config extends CI_Controller {

	 function __construct()
	 {
		parent::__construct();
 		$this->load->model('common/security_model');
		if($this->security_model->isAdminLogin() === FALSE){
          showmessage('请登录', 'admin/login/index', 3);
		}
		//加载缓存类
		$this->load->library('datacache');
		
	 }

	function index()
	{
		$data = array();
		$config = '';
		if ($this->input->post('thevaluesubmit')) {
			$config = $this->input->post('config');
			if (is_array($config)) {
				foreach ($config as $var => $value) {
					$value = addslashes(trim($value));
					if(strtolower(substr($value, 0, 3)) == 'my_') {
						continue;
					}
					$setarr[] = "('$var', '$value')";
				}
				
				$sql = "REPLACE INTO ".$this->db->dbprefix('config')." (var, datavalue) VALUES ".implode(',', $setarr);
				$this->db->query($sql);
				$this->datacache->config_cache();
				showmessage('操作成功','admin/admin_config', 2);
			}
		}
		$query = $this->db->get('config');
		foreach ($query->result_array() as $key => $row) {
			$config[$row['var']] = $row['datavalue'];
		}
		$data['configs'] = $config;
		$this->load->template('admin/admin_config_tpl', $data);
	}
}
?>